/**
 * Created by wubo on 2018/3/14.
 */
define(function(require, exports, module) {
    require("vue");
    require("element");

    var store = require("../event/event.index.js");
    var dataLoader = require("../dataLoader.js");
    var searchForm = require("./grid.form.js");

    var defaultOpt = {
        name:"grid",
        store:store,
        data:function(){
            return {
            	url:"",
                resObj:{},
            }
        },
        components:{

        },
        methods:{
            /**
             * 以下为pagination组件的监听事件 不在另写组件
             */
            handleCurrentChange:function(curPage) {
                var self = this;
                self.$store.dispatch("load",{page:curPage});
            },
            handleSizeChange:function(){
            }
        },
        watch:{
            "$store.getters.resObj":function(resObj){
                this.resObj = resObj;
            },
        },

        mounted:function(){
            this.$store.dispatch("load",{url:this.url})
        }
    }

    module.exports = function(options){
        var opts = $.extend(defaultOpt,
            {
        		data:function(){
        			return {
        				url:options.url,
        				resObj:{},
        			}
        		},
                components:{
                    "form":searchForm(options.form),
                    "dataLoader":dataLoader
                },
                template:options.gridTpl
            }
        );

        if(!opts.template)
            throw new Error("模板不能为空！");

        return Vue.extend(opts);
    }
})